$(function () {
  
    var technologyId = getQueryString("technologyId");
    //根据id从数据库中获取修改前的值
    $.post(
        "/citrusmonitor/technology.do?method=findById&technologyId="+technologyId,

        function (res) {
        	var data = res.data;
	         if(res.status==1){
	        	 console.log(setDate(data.publishTime))
	        	 $("#technology_id").val(data.technologyId);
	    	     $("#title").val(data.title);
	    	     $("#introduction").val(data.introduction);
	             $("#publisher").val(data.publisher);
	             $("#category").val(data.category);
//	             $("#file_path").val(data.filePath),
	             $("#publish_time").val(setDate(data.publishTime));
//	             $("#browse_count").val(data.browseCount)
	         }
        },
        "json"
    );
    //edit按钮绑定事件
    $("#edit").click(function () {
    	console.log($("#technology_id").val())
        $.post(
            "/citrusmonitor/technology.do?method=modify",
            {
                "technologyId": $("#technology_id").val(),
                "title": $("#title").val(),
                "introduction": $("#introduction").val(),
                "publisher": $("#publisher").val(),
                "category": $("#category").val(),
//                "filePath": $("#file_path").val(),
                "publishTime": $("#publish_time").val()
//                "browseCount": $("#browse_count").val()
            },
           function(res){
                console.log(res);
                res = JSON.parse(res);
                if(res.status==1){
                    alert("信息提示修改成功");
                    window.location.href="show.html";
                }else{
                    alert("信息提示修改失败");
                }}
        )
    })
})

function getQueryString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    console.log(reg );
    var r = window.parent.document.getElementById("rightframe").contentWindow.location.search.substr(1).match(reg);
    if(r!=null){
        return  unescape(r[2]);
    }
    return null;
}

function setDate(date){
	var newDate = new Date(Date.parse(date.replace(/-/g,   "/")));
	//格式化日，如果小于9，前面补0
	var day = ("0" + newDate.getDate()).slice(-2);
	//格式化月，如果小于9，前面补0
	var month = ("0" + (newDate.getMonth() + 1)).slice(-2);
	//拼装完整日期格式
	var result = newDate.getFullYear()+"-"+(month)+"-"+(day) ;
	return result;
}